package mine.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;


import com.xkh.xkh.MyApplication;
import com.xkh.xkh.R;
import com.orm.SugarRecord;

import bbs.activity.BbsMainActivity;
import bbs.model.User;
import chat.network.tcp.PushControlReceiver;
import chat.network.tcp.PushService;
import emergency.activity.EmergencyShow;
import managers.DatabaseManager;
import managers.UIHandler;
import managers.UserInfo;
import model.OwnUser;
import shuiyuqing.model.BasicInfoModel;
import shuiyuqing.network.http.GetBasicInfo;

/**
 * 我的基本信息
 * Created by 凯 on 2015/11/12.
 */
public class MyActivity extends UIHandler.BaseActivity {

    // 返回按钮
    Button btn_back;

    // 头像
    ImageView img_avar;

    // 帐号信息
    TextView tv_account;

    // 真实姓名
    TextView tv_realName;

    // 论坛
//    View v_luntan;

    // 退出
    View v_logout;

    // 报警纪录
    View v_emergency;


    TextView tv_id_content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        initview();
        initdata();
    }

    private void initdata() {
        OwnUser ownUser = MyApplication.getOwnUser();
        tv_account.setText(ownUser.getUser_NickName());
        tv_realName.setText(ownUser.getUser_RealName());
        tv_id_content.setText(ownUser.getUser_ID()+"");
    }


    // 点击按钮
    View.OnClickListener itemClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
//            if (v == v_luntan)
//            {
//                // 清空基本信息表
//                BasicInfoModel.clearBasicInfo();
//
//                showDialog();
//                // 重新获取
//                GetBasicInfo getBasicInfo = new GetBasicInfo();
//                getBasicInfo.get();
//                getBasicInfo.setRunnable(new Runnable() {
//                    @Override
//                    public void run() {
//                        closeDialog();
//                    }
//                });
//                Intent intent = new Intent(MyActivity.this, BbsMainActivity.class);
//                MyActivity.this.startActivity(intent);


//            }else

            if (v == v_logout)
            {
                Intent intent = new Intent(MyActivity.this, PushControlReceiver.class);
                intent.putExtra(PushService.SERVICE_ACTION, PushService.ACTION_DESTORY);
                MyActivity.this.sendBroadcast(intent);

                // 删除数据库
                DatabaseManager.getInstance().delete();
                // 退出所有界面
                UIHandler.uiHandler.finishiall();

                SugarRecord.deleteAll(model.OwnUser.class);
            }
            else if (v == btn_back)
            {
                finish();
            }
            else if (v == v_emergency)
            {
                Intent intent = new Intent(MyActivity.this, EmergencyShow.class);
                MyActivity.this.startActivity(intent);
            }
        }
    };

    // 初始化view
    private void initview() {

        btn_back = (Button) findViewById(R.id.id_btn_back);
        btn_back.setOnClickListener(itemClick);
        tv_account = (TextView) findViewById(R.id.id_tv_account);
        tv_realName = (TextView) findViewById(R.id.id_tv_realName);
//        v_luntan = findViewById(R.id.id_v_luntan);
//        v_luntan.setOnClickListener(itemClick);
        v_logout = findViewById(R.id.id_v_logout);
        v_logout.setOnClickListener(itemClick);

        img_avar = (ImageView) findViewById(R.id.id_img_avar);

        v_emergency = findViewById(R.id.id_v_emergency);
        v_emergency.setOnClickListener(itemClick);

        tv_id_content = (TextView) findViewById(R.id.id_tv_id_content);

    }
}
